package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.system.borrow.MyApplication;
import com.system.borrow.R;
import com.system.borrow.bean.TuiJian;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/11/30 17:05
 * 描    述：推荐适配器
 * ================================================
 */
public class TuiJianAdapter extends BaseAdapter{
    public Context context;
    public LayoutInflater inflater;
    int type = 0;
    private List<TuiJian> list = new ArrayList<>();
    public TuiJianAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public List<TuiJian> getList() {
        return list;
    }

    public void setList(List<TuiJian> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if(view==null){
            view = inflater.inflate(R.layout.item_tuijian,null);
            viewHolder = new ViewHolder();
            viewHolder.line = view.findViewById(R.id.line);
            viewHolder.rl_all = (RelativeLayout) view.findViewById(R.id.rl_all);
            viewHolder.iv_img = (ImageView) view.findViewById(R.id.iv_img);
            viewHolder.tv_name = (TextView) view.findViewById(R.id.tv_name);
            viewHolder.tv_count = (TextView) view.findViewById(R.id.tv_count);
            viewHolder.tv_tab = (TextView) view.findViewById(R.id.tv_tab);
            viewHolder.tv_yue = (TextView) view.findViewById(R.id.tv_yue);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        if(type==0){
            viewHolder.line.setVisibility(View.VISIBLE);
        }else{
            if(i==0){
                viewHolder.line.setVisibility(View.GONE);
            }else{
                viewHolder.line.setVisibility(View.VISIBLE);
            }
        }
        TuiJian tuiJian = list.get(i);
        MyApplication.imageLoader.displayImage(tuiJian.img,viewHolder.iv_img);
        viewHolder.tv_name.setText(tuiJian.name);
        viewHolder.tv_tab.setText(tuiJian.tag);
        viewHolder.tv_count.setText(tuiJian.applyCount);
        viewHolder.tv_yue.setText(tuiJian.monthRate);
        return view;
    }
    public class ViewHolder{
        View line;
        ImageView go,iv_img;
        RelativeLayout rl_all;
        TextView tv_name,tv_count,tv_yue;
        TextView tv_tab;
    }
}
